<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>


<form:form id="sparepartForm" commandName="model" cssClass="validate"
	action="sparepart/sparepart/save">
	<form:hidden path="id" />
	<div class="header">
		<h2>
			&nbsp;&nbsp;备件产品信息<span><font color="red">（* 为必填项）</font> </span>
		</h2>
	</div>

	<table class=" form-table">
		<tr>
			<td class="td1">编号：</td>
			<td class="td2"><form:input path="code" />
			</td>
		</tr>
		<tr>
			<td class="td1">备件分类：</td>
			<td class="td2"><form:hidden path="sptSparepartCategoryId" /> <isperp:treeSelector
					id="selectParentProjectCategory" url="sparepart/category/getTree"
					valueControlId="sptSparepartCategoryId"
					displayValue="${categoryName}" displayValueCssClass="required"></isperp:treeSelector>
			</td>
		</tr>
		<tr>
			<td class="td1">名称：</td>
			<td class="td2"><form:input path="name" cssClass="required" />
			</td>
		</tr>
		<tr>
			<td class="td1">型号：</td>
			<td class="td2"><form:input path="model" cssClass="required" />
			</td>
		</tr>
		<tr>
			<td class="td1">单位：</td>
			<td class="td2"><form:input path="unit" cssClass="required"
					cssStyle="width:70px" /></td>
		</tr>
		<c:if test="${curUserName eq 'admin' }">
		<tr style="">
			<td class="td1">当前库存：</td>
			<td class="td2"><form:input path="curStockQuantity" cssClass="required"
					cssStyle="width:70px" /></td>
		</tr>
		<tr style="">
			<td class="td1">报废数：</td>
			<td class="td2"><form:input path="discardQuantity" cssClass="required"
					cssStyle="width:70px" /></td>
		</tr>
		<tr style="">
			<td class="td1">维修数：</td>
			<td class="td2"><form:input path="repairQuantity" cssClass="required"
					cssStyle="width:70px" /></td>
		</tr>
		</c:if>
		<tr>
			<td class="td1">最小库存：</td>
			<td class="td2"><form:input path="minStock" cssClass="number" />
				<div style="padding:8px 2px">
					<form:checkbox path="minStockUseRule"
						onchange="minStockUseRule_onchange()" label="是否使用规则" />
					（说明：库存规则可实现对最小库存动态监控）
					<div id="isMinStockUseRule" style="padding:5px 0">

						比例值：
						<form:input path="minStockUseRuleProportion" cssClass="number" />
						<input type="hidden" id="categoryIdValue" name="categoryIdValue" />

						<div class="box no-border">
							<div class="box-left">
								<isperp:tree id="categoryTree" title="配置分类">
									<isperp:async enable="true" url="">
									</isperp:async>
									<isperp:check enable="true"></isperp:check>
								</isperp:tree>
							</div>
							<div class="box-right">${model.minStockUseRuleDesc }</div>
						</div>

					</div>
				</div>
			</td>
		</tr>
	</table>


</form:form>

<isperp:buttonList>
	<button class="submit"
		onclick="setCheckedCategoryTreeNodes();isperp.submitForm({success : function() { isperp.reloadGrid('sparepartGrid');isperp.closeDialog(); }}); return false;">
		<span class="icon icon-save"></span>提交
	</button>
</isperp:buttonList>
<script type="text/javascript">
	function setCheckedCategoryTreeNodes() {

		var nodes = categoryTree.zTree.getCheckedNodes(true);

		var nStr = "";
		$(nodes).each(function(index, node) {
			nStr += node.id + ",";
		});

		$("#categoryIdValue").val(nStr);
		return true;
	}

	function minStockUseRule_onchange() {

		var minStockUseRuleCheck = $("input[name='minStockUseRule']:checked").val();

		if (minStockUseRuleCheck) {

			$("#isMinStockUseRule").show();
			$("#minStock").hide();
			var treeObj = $.fn.zTree.getZTreeObj("categoryTree");
			treeObj.setting.async.url = "sparepart/sparepart/getConfCategorys?sparepartId=${model.id}";

			categoryTree.reload();

		} else {
			$("#isMinStockUseRule").hide();
			$("#minStock").show();
		}

	}

	minStockUseRule_onchange();
</script>
